/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DelAlbum.java
 *
 * Created on 19-mar-2009, 22:28:34
 */

package edu.upf.grupE.interftest;

import edu.upf.grupE.Entities.Album;
import edu.upf.grupE.impl.GUILogic;
import java.util.ArrayList;
import java.util.Vector;

/**
 *
 * @author Oscar
 */
public class DelAlbum extends javax.swing.JFrame {
    ImageSelection im;
    VideoSelection vid;
    ArrayList albumss= new ArrayList();
    /** Creates new form DelAlbum */
    public DelAlbum(ImageSelection im, VideoSelection vid) {
        this.im=im;
        this.vid=vid;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBox1 = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        this.DeleteItems();
        this.setAlbums();

        jButton1.setText("Delete");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Cancel");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(42, 42, 42)
                        .addComponent(jButton1)
                        .addGap(41, 41, 41)
                        .addComponent(jButton2))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(94, 94, 94)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(59, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(47, 47, 47)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap(34, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        Album eliminado= (Album)albumss.get(jComboBox1.getSelectedIndex());
        GUILogic.DeleteAlbum(eliminado.getId());
        this.DeleteItems();
        this.setAlbums();
        im.UpdateAlbums();
        vid.UpdateAlbums();
        dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void setAlbums(){
        for(int i=0; i<albumss.size();i++){
            albumss.remove(0);
        }
        Vector <Album> albums= GUILogic.getListAlbums();
        for(int i=0; i<albums.size(); i++){
    if(albums.get(i).getId()!=1L){
    jComboBox1.addItem(albums.get(i).getName());
    albumss.add(albums.get(i));
    }
}
    }
    private void DeleteItems(){
        if(jComboBox1.getItemCount()>0){
        jComboBox1.removeAllItems();}
    }

    /**
    * @param args the command line arguments
    */
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JComboBox jComboBox1;
    // End of variables declaration//GEN-END:variables

}
